package com.sx.zongzhi.adapter;


import android.content.Context;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;

import com.sx.zongzhi.R;
import com.sx.zongzhi.bean.ProcessBean;
import com.sx.zongzhi.utils.BaseUtil;
import com.zhy.adapter.abslistview.CommonAdapter;
import com.zhy.adapter.abslistview.ViewHolder;

import java.util.List;

/**
 * Created by XZY on 2017/11/23.
 * 事件办理过程
 */
public class DealProcessAdapter extends CommonAdapter<ProcessBean> {


    private Context context;

    public DealProcessAdapter(Context context, int layoutId, List<ProcessBean> datas) {
        super(context, layoutId, datas);
        this.context=context;
    }


    @Override
    protected void convert(ViewHolder viewHolder, final ProcessBean item, int position) {
        ImageView imageView=viewHolder.getView(R.id.imv_Hint);
        if (position==0){
            imageView.setImageResource(R.mipmap.icon_process_selected);
        }else {
            imageView.setImageResource(R.mipmap.icon_process_normal);
        }
        viewHolder.setText(R.id.tv_Time,item.getDealTime());
        viewHolder.setText(R.id.tv_Title,item.getDealDescribe());
        String content= BaseUtil.isEmpty(item.getContent())?"":item.getContent();
        viewHolder.setText(R.id.tv_Content,"并留言："+content);

        RecyclerView view = viewHolder.getView(R.id.recyclerView);
        if (item.getFiles() != null && item.getFiles() .size() > 0) {
            view.setVisibility(View.VISIBLE);
            view.setLayoutManager(new LinearLayoutManager(context, LinearLayout.HORIZONTAL, false));
            final PictureAdapter pictureAdapter = new PictureAdapter(context, item.getFiles());
            view.setAdapter(pictureAdapter);
//            pictureAdapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
//                @Override
//                public void onItemClick(final BaseQuickAdapter adapter, View view, final int position) {
//                    String type = item.getFiles().get(position).getSuffixType();
//                    String path = ServiceFactory.NEW_API_BASE_URL+ File.separator+item.getFiles().get(position).getPath();
//                    if(".mp4".equalsIgnoreCase(type)){
//                        context.startActivity(new Intent(context,
//                                VideoPlayerActivity.class).putExtra(
//                                "path",path));
//                    }else if(".wav".equalsIgnoreCase(type) || ".amr".equalsIgnoreCase(type)){
//                        int isPlayingPostion = 0;
//                        for(int i = 0 ; i < item.getFiles().size() ; i++){
//                            if (item.getFiles().get(i).isPlay){
//                                isPlayingPostion = i;
//                                break;
//                            }
//                        }
//                        if (player == null){
//                            player = new Player(context);
//                        }
//                        if (player.isPlay() && isPlayingPostion == position){
//                            player.stop();
//                            item.getFiles().get(isPlayingPostion).isPlay = false;
//                            adapter.notifyDataSetChanged();
//                        }else if (player.isPlay() && isPlayingPostion != position){
//                            player.stop();
//                            item.getFiles().get(isPlayingPostion).isPlay = false;
//                            item.getFiles().get(position).isPlay = true;
//                            adapter.notifyDataSetChanged();
//                            player.playUrl(path,null, new Player.OnCompletionListener() {
//                                @Override
//                                public void onPlayComplet() {
//                                    item.getFiles().get(position).isPlay = false;
//                                    pictureAdapter.notifyDataSetChanged();
//                                }
//                            });
//                        }else {
//                            item.getFiles().get(position).isPlay = true;
//                            adapter.notifyDataSetChanged();
//                            player.playUrl(path,null,new Player.OnCompletionListener() {
//                                @Override
//                                public void onPlayComplet() {
//                                    item.getFiles().get(position).isPlay = false;
//                                    adapter.notifyDataSetChanged();
//                                }
//                            });
//                        }
//                    }else if (".jpeg".equalsIgnoreCase(type)||".png".equalsIgnoreCase(type)||
//                            ".jpg".equalsIgnoreCase(type)){
//                        context.startActivity(new Intent(context, ImagePlayActivity.class).putExtra(
//                                "path", path));
//                    }else {
//                        ToastUtils.showToast(context,"不能查看文件");
//                    }
 //               }
//            });

        }else {
            view.setVisibility(View.GONE);
        }
    }
}
